/*
 * @Author: zhangdong 354266323@qq.com
 * @Date: 2022-06-07 16:56:52
 * @LastEditors: zhangdong 354266323@qq.com
 * @LastEditTime: 2022-06-08 15:10:59
 * @FilePath: \logistics-sunshine-unattended-app\store\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
  state: {
    test: '我是仓库测试数据',
    token: '',
    wasSubscribed: false,
    hasLogin: false,
    userInfo: {},
    identity: '',//身份类别
  },
  mutations: {
    getNativeToken (state, token) {
      state.token = token
    },
    getNativeWasSubscribed (state, wasSubscribed) {
      state.wasSubscribed = wasSubscribed
    },
    login (state, provider) {

      state.hasLogin = true;
      state.userInfo = provider;
      uni.setStorageSync('userInfo', provider)
    },
    logout (state) {
      state.hasLogin = false;
      state.userInfo = {};
      state.identity = '';
      uni.removeStorage({
        key: 'userAccount'
      })
      uni.removeStorage({
        key: 'userInfo'
      })
      uni.removeStorage({
        key: 'accountId'
      })
      uni.reLaunch({
        url: '/pages/login/login',
      })
    },
    setidentity (state, identity) {
      state.identity = identity
    }
  },
  actions: {
    getNativeToken ({ commit }, token) {
      commit('getNativeToken', token)
    },
    getNativeWasSubscribed ({ commit }, wasSubscribed) {
      commit('getNativeWasSubscribed', wasSubscribed)
    },
    getIdentity ({ commit }, identity) {
      commit('setidentity', identity)
    },
  }
})
export default store